package java_thinking.unit_18_IO._18_6;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

/**
 * @Desc:   将读入的文件存入LinkedList中再遍历出来
 * @author: cww
 * @DateTime: 2019/5/14 16:59
 */

public class E07_FileIntoList {
    public static List<String> read(String fileName) throws IOException {
        BufferedReader reader = new BufferedReader(new FileReader(fileName));
        String s;
        List<String> list = new LinkedList<String>();
        while ((s = reader.readLine()) != null) {
            list.add(s);
        }
        reader.close();
        return list;
    }

    public static void main(String[] args) throws IOException {
        List<String> list = read("cache/test3.txt");
        for (ListIterator<String> it = list.listIterator(list.size()); it.hasPrevious();) {
            String s = it.previous();
            if (s.indexOf("test") != -1) {
                System.out.println("index: "+ s);
            }
            System.out.println(s.toUpperCase());
        }
    }

}
